<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021-07-16
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Layui</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js" ></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="demoTable layui-form">
    <div class="layui-inline" style="margin-top: 15px">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <select id="branchidSel" name="branchid" lay-verify="required">
                    <option value="">选择搜索的门店</option>
                </select>
            </div>
        </div>
    </div>
    <button class="layui-btn" id="reloadTabBtn" data-type="reload">搜索</button>
</div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<%--查询所有的出库详情表--%>
<div id="divEle3" style="display: none">
    <table id="demo3" lay-filter="test3" ></table>
    <%--<h1>总计：元</h1>--%>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <%--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>--%>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">刷新</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <%--{{#  if(d.state == 1){ }}
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="adopt">通过</button>
    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="reject">驳回</button>
    {{#  } else { }}
    {{#  } }}--%>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="detailed">详细信息</button>
</script>
<script type="text/html" id="titleTpl">
    {{#  if(d.examstate == 1){ }}
    <button class="layui-btn layui-btn-warm layui-btn-sm" style="width: 70px">待审核</button>
    {{# } else if(d.examstate == 2){ }}
    <button class="layui-btn layui-btn-sm"  style="width: 70px">审核通过</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-danger layui-btn-sm"style="width: 70px">审核驳回</button>
    {{#  } }}
</script>

<script type="text/html" id="DeliveryMode">
    {{#  if(d.outmethod == 1){ }}
    <button class="layui-btn layui-btn-radius layui-btn-sm" >零售出库</button>
    {{# } else if(d.outmethod == 2){ }}
    <button class="layui-btn layui-btn-radius layui-btn-normal layui-btn-sm">批量出库</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm">平调出库</button>
    {{#  } }}
</script>


<script>
    function dateStr(data){
        var y = data.year;
        // alert(y)
        var M = data.monthValue;
        var d = data.dayOfMonth;
        var H = data.hour;
        var m = data.minute;
        var s = data.second;
        var str = y + "-" + M + "-" + d + "  " + H + ":" + m + ":" +s;
        return str;
    }
    layui.use(['table','jquery','form','layer'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;

        $.ajax({
            url: '${pageContext.request.contextPath}/type/getAllType',
            type: 'get',
            dataType: 'json',
            success: function (types) {
                console.log(types)
                $.each(types, function (i, obj) {
                    $("#branchidSel").append(
                        $("<option></option>").attr("value", obj.branchid).text(obj.branchname)
                    )
                })
                form.render('select');
            }
        })

        $("#reloadTabBtn").click(function (){
            table.reload('tb',{
                where: { //设定异步数据接口的额外参数
                    bid:$("#branchidSel").val()
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        })



        //出库信息
        table.render({
            elem: '#test'
            ,id:'tb'
            ,url:'${pageContext.request.contextPath}/out/getAllOutLibrary1'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,title: '出库信息表'
            ,text:{
                none:"无数据"
            }
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'cid', title:'出库编号',fixed: 'left'}
                ,{field:'outstaffname', title:'出库人'}
                ,{field:'outtime', title:'出库时间',templet:function (d) {
                        return dateStr(d.outtime);}}
                ,{field:'examstaffname', title:'审核人'}
                ,{field:'examtime', title:'审核时间',
                    templet:function (d) {
                        return d.examtime==null?'':dateStr(d.examtime);}
                }
                ,{field:'outmethod', title:'出库方式',templet: '#DeliveryMode'}
                ,{field:'examstate', title:'审核状态',templet:'#titleTpl'}
                ,{field:'branchname', title:'所属分店'}
                ,{field:'remarks', title:'驳回理由'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page:true,//开启分页
            limit:5,//默认每页显示的条数
            limits:[5,10,15,20],//自定义分页条数的选择
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                   table.reload('tb')
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(obj)
            if(obj.event === 'detailed'){
                layer.open({
                    type: 1,
                    content: $("#divEle3"), //这里content是一个普通的String
                    area: ['780px' ,'400px'],
                    offset: 't'
                });

                table.render({
                    id:"test3",
                    //elem element 元素---》表格的容器
                    elem: '#demo3'//table标签的id属性值
                    //,height: 312//整个表格的高度
                    ,url: '${pageContext.request.contextPath}/outLibrary/outLibraryDetails' //数据接口
                    ,cols: [[ //表头
                        {type: 'checkbox', fixed: 'left'}
                        ,{field: 'xid', title: '出库详情ID'}
                        ,{field: 'cid', title: '出库表id',hide:true}
                        ,{field: 'goodsid', title: '商品ID',hide:true}
                        ,{field: 'goodsname', title: '商品名'}
                        ,{field: 'num', title: '出库数量'}
                        ,{field: 'sprice', title: '售价'}
                        ,{field: 'total', title: '总价'}
                        /* ,{field: 'right', title:'操作', toolbar: '#barDemo'}*/
                    ]],
                    page:true,//开启分页
                    limit:5,//默认每页显示的条数
                    limits:[5,10,15,20],//自定义分页条数的选择
                    where:{
                        cid:data.cid
                    }
                });
            }
        });
    });
</script>

</body>
</html>
